using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

// use these:

using LiquidFireArts.Wormhole.Misc;
using LiquidFireArts.Sampler;

namespace Unibot
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class UnibotGame : Microsoft.Xna.Framework.Game
    {

        public TextureGenerator textureGenerator;

        SampleManager _SampleManager;
        SpriteBatch spriteBatch;

        GraphicsDeviceManager graphics;
        public int currentlevel;
        private Player[] players;
        public Player getPlayer(int i){ return players[i-1];}

        private GameState prevstate;
        public GameState getPrevState() { return prevstate; }
        private GameState currentstate; //Current state, may determine ScreenSwap
        public GameState getCurrentState() { return currentstate; }
        public void setCurrentState(GameState state)
        {
            prevstate = currentstate; 
            currentstate = state;
        }

        private Screen currentscreen; //the screen currently shown
        public void changeScreen(Screen newScreen)
        {
            currentscreen = newScreen;
        }

        public UnibotGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            //players = new Player[1];
            

            graphics.PreferredBackBufferHeight = Constants.FixedDrawingHeight;
            graphics.PreferredBackBufferWidth = Constants.FixedDrawingWidth;

        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any elements
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            SpriteSheet.InitializeSprites(this.Content);
            currentscreen = new TitleScreen(this);

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // TODO: use this.Content to load your game content here
            textureGenerator = new TextureGenerator(GraphicsDevice);

                        // a font for the description text
            SpriteFont font = Content.Load<SpriteFont>("Fonts/LucidaConsole");
            // create the SampleManager first
           // _SampleManager = new SampleManager(this, font);
            Fonts.loadFonts(this.Content);

        //    _SampleManager.Activate();
         //   _SampleManager.ManagerTextColor = Color.DarkTurquoise;
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
            Content.Unload();
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit

            if (MyGamePad.GetState(PlayerIndex.One).Buttons.Select == ButtonState.Pressed)
                this.Exit();

           // _SampleManager.Update(gameTime);
            currentscreen.Update(gameTime);
            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.White);

            //_SampleManager.Draw(gameTime, spriteBatch);
            //_SampleManager.Update(gameTime);
            currentscreen.Draw(gameTime);

            // TODO: Add your drawing code here
            
            base.Draw(gameTime);
        }

        public TextureGenerator getTextureGenerator()
        {
            return this.textureGenerator;
        }

        public SpriteBatch getSpriteBatch()
        {
            return this.spriteBatch;
        }

    }
}
